home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12511 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  55.1 KB

  1. Path: elektron.et.tudelft.nl!news
  2. From: Martin van Velsen <velzen@kgs.twi.tudelft.nl>
  3. Newsgroups: comp.lang.c++
  4. Subject: 3ds-bin format ( new ) + source
  5. Date: 20 Mar 1996 09:04:11 GMT
  6. Organization: Delft University of Technology, Dept. of Electrical Engineering
  7. Message-ID: <4iohmb$7kf@elektron.et.tudelft.nl>
  8. NNTP-Posting-Host: dutise.twi.tudelft.nl
  9. Mime-Version: 1.0
  10. Content-Type: multipart/mixed;
  11.     boundary="-------------------------------47423551520711978481135565041"
  12. X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.3 sun4c)
  13. X-URL: file:/home/velzen/3DS_BIN.DOC
  14.  
  15. This is a multi-part message in MIME format.
  16.  
  17. ---------------------------------47423551520711978481135565041
  18. Content-Transfer-Encoding: 7bit
  19. Content-Type: text/plain; charset=us-ascii
  20.  
  21. -- 
  22.                             oooo
  23.          ooOOOo           oOOOOOOOo
  24.        oOOOOOOOOo        OOOOOOOOOOO
  25.    oO[]OOOOOO[]OOo      OO "OOOOOOOO[
  26.   OOO OOOOOOO" "OOo    OOO" "OOOOOO"
  27.  ]OOO "OOOOO" "o "OOo oOO[ "o """"
  28.  ]OOOOo """ o   " "OO OO"
  29.   "OOOO"  "OO[ oOOo " " oOOOo
  30.     ""      O OOOOOOO[]OOOOOOo
  31.           oo[]OOOO[.O[][.OOOOO[
  32.         oOOO "OOOOOOO[]OOOOOOO
  33.        OOO" oo"OOOO" oo ""O" oO"Oo
  34.        "O oO" Ooooo       ooOOO" OO[
  35.        o[]OOOo OOOOOOoooOOOOOO"oOO"
  36.      oOOO "OO"o "OOOOOOOOOOO"
  37.     ]OOOOOooooOO o ""OOO"" o
  38.      "OOOOOOOOOO "OO      OO
  39.          ""OOOOOOo O[     OO
  40.             "OOO"" O[    oOOo
  41.               O oOOOOo oOOOOOOo
  42.                ]OOOOOOO OOOOOO"
  43.                o "OOOOOOOO"""    
  44. *--------------------------------------------*
  45. Martin van Velsen
  46. email: odi@ronix.ptf.hro.nl
  47. or:    0347612@ptfe22.hro.nl
  48. or:    velzen@kgs.twi.tudelft.nl
  49.  
  50. ( Currently working at the Technical University Delft )
  51. *--------------------------------------------*
  52.  
  53. ---------------------------------47423551520711978481135565041
  54. Content-Transfer-Encoding: 7bit
  55. Content-Type: text/plain
  56.  
  57.  
  58.                           3D-Studio File Format (.3ds)
  59.                                  Autodesk Ltd.
  60.  
  61.    Document Revision 0.9 - March 1996
  62.  
  63.    Rewritten by Martin van Velsen (email: vvelsen@ronix.ptf.hro.nl )
  64.    Based on Original document by Jim Pitts ( email: jp5.ukc.ac.uk )
  65.  
  66.    A lot of the chunks are still undocumented if you know what they do
  67.    please email me or Jimm Pitts. As I get more information of the file format,
  68.    I will document it for everyone to see. I will post this regurlarly to alt.3d
  69.    and alt.3d-studio and I can be contacted there if my email does not work.
  70.  
  71.    Disclaimer.
  72.    This document describes the file format of the 3ds files generated by
  73.    3d-studio by Autodesk. By using the information contained within you agree
  74.    not to hold me or Jim Pitts liable if, from its use, you f^Hmuck something
  75.    up. OK?
  76.  
  77.  
  78. 0. A warning beforehand. This docs describes the format of 3ds files produced
  79.    by version 3.0 and higher of 3d-studio. You can find this information at
  80.    byte 29 in the binary file.
  81.  
  82.  
  83. 1. The 3ds file format is made up of chunks. They describe what information
  84.    is to follow and what it is made up of, it's ID and the location of the
  85.    next block. IF you don't understand a chunk you can quite simply skip it.
  86.    The next chunk pointer is relative to the start of the current chunk and
  87.    in bytes. The binary information in the 3ds file is written in a special
  88.    kind of way. Namely the lest significant byte comes first in an int.
  89.    For example: 4A 5C  (2 bytes in hex) would be 5C high byte and 4A low byte. In a long it
  90.    is: 4A 5C 3B 8F where 5C4A is the low word and 8F 3B is the high word.
  91.    And now for the chunks. A chunk is defined as:
  92.  
  93.    start end size name
  94.    0     1   2    Chunk ID
  95.    2     5   4    Pointer to next chunk relative to the place where
  96.                   Chunk ID is, in other words the length of the chunk
  97.  
  98.    Chunks have a hierarchy imposed on them that is identified byt it's ID.
  99.    A 3ds file has the Primary chunk ID 4D4Dh. This is always the first
  100.    chunk of the file. Within the primary chunk are the main chunks.
  101.  
  102.    to give you a preview and a reference to the hierarchy of chunks, below is
  103.    a diagram to show the diffrent chunk ID's and their place in the file.
  104.    The chunks are given a name because below the diagram is a list which
  105.    defines the names to the actual chunk id's. This makes it easier to
  106.    put it in some source code ( how convenient that some sample code is
  107.    included )
  108.  
  109.                   MAIN3DS
  110.                   |
  111.                   +--EDIT3DS
  112.                   |  |
  113.                   |  +--EDIT_MATERIAL
  114.                   |  |  |
  115.                   |  |  +--MAT_NAME01
  116.                   |  |  +--MAT_UNKNWN01
  117.                   |  |  +--MAT_UNKNWN02
  118.                   |  |  +--MAT_UNKNWN03
  119.                   |  |  +--MAT_UNKNWN04
  120.                   |  |  +--MAT_UNKNWN05
  121.                   |  |  +--MAT_UNKNWN06
  122.                   |  |  +--MAT_UNKNWN07
  123.                   |  |  +--MAT_UNKNWN08
  124.                   |  |  +--MAT_UNKNWN09
  125.                   |  |  +--MAT_UNKNWN10
  126.                   |  |  +--MAT_UNKNWN11
  127.                   |  |
  128.                   |  +--EDIT_CONFIG1
  129.                   |  +--EDIT_CONFIG2
  130.                   |  +--EDIT_VIEW_P1
  131.                   |  |  |
  132.                   |  |  +--TOP
  133.                   |  |  +--BOTTOM
  134.                   |  |  +--LEFT
  135.                   |  |  +--RIGHT
  136.                   |  |  +--FRONT
  137.                   |  |  +--BACK
  138.                   |  |  +--USER
  139.                   |  |  +--CAMERA
  140.                   |  |  +--LIGHT
  141.                   |  |  +--DISABLED
  142.                   |  |  +--BOGUS
  143.                   |  |
  144.                   |  +--EDIT_VIEW_P2
  145.                   |  |  |
  146.                   |  |  +--TOP
  147.                   |  |  +--BOTTOM
  148.                   |  |  +--LEFT
  149.                   |  |  +--RIGHT
  150.                   |  |  +--FRONT
  151.                   |  |  +--BACK
  152.                   |  |  +--USER
  153.                   |  |  +--CAMERA
  154.                   |  |  +--LIGHT
  155.                   |  |  +--DISABLED
  156.                   |  |
  157.                   |  +--EDIT_VIEW_P2
  158.                   |  +--EDIT_VIEW1
  159.                   |  +--EDIT_BACKGR
  160.                   |  +--EDIT_AMBIENT
  161.                   |  +--EDIT_OBJECT
  162.                   |  |  |
  163.                   |  |  +--OBJ_TRIMESH
  164.                   |  |  |  +--TRI_VERTEXL
  165.                   |  |  |  +--TRI_FACEL2
  166.                   |  |  |  +--TRI_FACEL1
  167.                   |  |  |  +--TRI_SMOOTH
  168.                   |  |  |  +--TRI_TRANSL
  169.                   |  |  |  +--TRI_VISIBLE
  170.                   |  |  |
  171.                   |  |  +--OBJ_LIGHT
  172.                   |  |  |  |
  173.                   |  |  |  +--LIT_OFF
  174.                   |  |  |  +--LIT_SPOT
  175.                   |  |  |  +--LIT_UNKNWN01
  176.                   |  |  |
  177.                   |  |  +--OBJ_CAMERA
  178.                   |  |  |  |
  179.                   |  |  |  +--CAM_UNKNWN01
  180.                   |  |  |  +--CAM_UNKNWN02
  181.                   |  |  |
  182.                   |  |  +--OBJ_UNKNWN01
  183.                   |  |  +--OBJ_UNKNWN02
  184.                   |  |
  185.                   |  +--EDIT_UNKNW01
  186.                   |  +--EDIT_UNKNW02
  187.                   |  +--EDIT_UNKNW03
  188.                   |  +--EDIT_UNKNW04
  189.                   |  +--EDIT_UNKNW05
  190.                   |  +--EDIT_UNKNW06
  191.                   |  +--EDIT_UNKNW07
  192.                   |  +--EDIT_UNKNW08
  193.                   |  +--EDIT_UNKNW09
  194.                   |  +--EDIT_UNKNW10
  195.                   |  +--EDIT_UNKNW11
  196.                   |  +--EDIT_UNKNW12
  197.                   |  +--EDIT_UNKNW13
  198.                   |  +--EDIT_UNKNW14
  199.                   |
  200.                   +--KEYF3DS
  201.  
  202.  A chunk type which you can find all through the file are the color chunks
  203.  which are called:
  204.  
  205.  COL_RGB
  206.  COL_TRU
  207.  COL_UNK
  208.  
  209.  Now for the actual numbers, as you will see I used the define, because I
  210.  ripped that part right out of my code. Be carefull however because there
  211.  are a lot of new chunk types which were not documented in the original paper
  212.  by Jim Pitts.
  213.  
  214.  //>------ Primary chunk
  215.  
  216.  #define MAIN3DS       0x4D4D
  217.  
  218.  //>------ Main Chunks
  219.  
  220.  #define EDIT3DS       0x3D3D  // this is the start of the editor config
  221.  #define KEYF3DS       0xB000  // this is the start of the keyframer config
  222.  
  223.  //>------ sub defines of EDIT3DS
  224.  
  225.  #define EDIT_MATERIAL 0xAFFF
  226.  #define EDIT_CONFIG1  0x0100
  227.  #define EDIT_CONFIG2  0x3E3D
  228.  #define EDIT_VIEW_P1  0x7012
  229.  #define EDIT_VIEW_P2  0x7011
  230.  #define EDIT_VIEW_P3  0x7020
  231.  #define EDIT_VIEW1    0x7001
  232.  #define EDIT_BACKGR   0x1200
  233.  #define EDIT_AMBIENT  0x2100
  234.  #define EDIT_OBJECT   0x4000
  235.  
  236.  #define EDIT_UNKNW01  0x1100
  237.  #define EDIT_UNKNW02  0x1201
  238.  #define EDIT_UNKNW03  0x1300
  239.  #define EDIT_UNKNW04  0x1400
  240.  #define EDIT_UNKNW05  0x1420
  241.  #define EDIT_UNKNW06  0x1450
  242.  #define EDIT_UNKNW07  0x1500
  243.  #define EDIT_UNKNW08  0x2200
  244.  #define EDIT_UNKNW09  0x2201
  245.  #define EDIT_UNKNW10  0x2210
  246.  #define EDIT_UNKNW11  0x2300
  247.  #define EDIT_UNKNW12  0x2302 // new chunk type
  248.  #define EDIT_UNKNW13  0x3000
  249.  #define EDIT_UNKNW14  0xAFFF
  250.  
  251.  //>------ sub defines of EDIT_MATERIAL
  252.  #define MAT_NAME01    0xA000  //> includes name
  253.  #define MAT_UNKNWN01  0xA010
  254.  #define MAT_UNKNWN02  0xA020
  255.  #define MAT_UNKNWN03  0xA030
  256.  #define MAT_UNKNWN04  0xA040
  257.  #define MAT_UNKNWN05  0xA041
  258.  #define MAT_UNKNWN06  0xA050
  259.  #define MAT_UNKNWN07  0xA052
  260.  #define MAT_UNKNWN08  0xA053
  261.  #define MAT_UNKNWN09  0xA100
  262.  #define MAT_UNKNWN10  0xA084
  263.  #define MAT_UNKNWN11  0xA087
  264.  
  265.  //>------ sub defines of EDIT_OBJECT
  266.  #define OBJ_TRIMESH   0x4100
  267.  #define OBJ_LIGHT     0x4600
  268.  #define OBJ_CAMERA    0x4700
  269.  
  270.  #define OBJ_UNKNWN01  0x4010
  271.  #define OBJ_UNKNWN02  0x4012 //>>---- Could be shadow
  272.  
  273.  //>------ sub defines of OBJ_CAMERA
  274.  #define CAM_UNKNWN01  0x4710 // new chunk type
  275.  #define CAM_UNKNWN02  0x4720 // new chunk type
  276.  
  277.  //>------ sub defines of OBJ_LIGHT
  278.  #define LIT_OFF       0x4620
  279.  #define LIT_SPOT      0x4610
  280.  #define LIT_UNKNWN01  0x465A
  281.  
  282.  //>------ sub defines of OBJ_TRIMESH
  283.  #define TRI_VERTEXL   0x4110
  284.  #define TRI_FACEL2    0x4111 // unknown yet
  285.  #define TRI_FACEL1    0x4120
  286.  #define TRI_SMOOTH    0x4150
  287.  #define TRI_TRANSL    0x4160
  288.  #define TRI_VISIBLE   0x4165
  289.  
  290.  //>>------ sub defs of KEYF3DS
  291.  
  292.  #define KEYF_UNKNWN01 0xB009
  293.  #define KEYF_UNKNWN02 0xB00A
  294.  #define KEYF_FRAMES   0xB008
  295.  #define KEYF_OBJDES   0xB002
  296.  
  297.  //>>------  these define the different color chunk types
  298.  #define COL_RGB  0x0010
  299.  #define COL_TRU  0x0011
  300.  #define COL_UNK  0x0013 // unknown
  301.  
  302.  //>>------ defines for viewport chunks
  303.  
  304.  #define TOP           0x0001
  305.  #define BOTTOM        0x0002
  306.  #define LEFT          0x0003
  307.  #define RIGHT         0x0004
  308.  #define FRONT         0x0005
  309.  #define BACK          0x0006
  310.  #define USER          0x0007
  311.  #define CAMERA        0x0008 // 0xFFFF is the actual code read from file
  312.  #define LIGHT         0x0009
  313.  #define DISABLED      0x0010
  314.  #define BOGUS         0x0011
  315.  
  316.  So far for the quick stuff now the more detailed info.
  317.  
  318.  * Main chunks
  319.  
  320.    id
  321.  
  322.   3D3D Start of Editor data  ( this is also the place where the objects are )
  323.   B000 Start of Keyframer data
  324.  
  325.   Directly after a Main chunk is another chunk. This could be any other type
  326.   of chunk allowable within its main chunks scope. ( see diagram )
  327.  
  328.  * Subchunks of 3D3D
  329.   id   Description
  330.  0100  Part of configuration
  331.  1100  unknown
  332.  1200  Background Color
  333.  1201  unknown
  334.  1300  unknown
  335.  1400  unknown
  336.  1420  unknown
  337.  1450  unknown
  338.  1500  unknown
  339.  2100  Ambient Color Block
  340.  2200  fog ?
  341.  2201  fog ?
  342.  2210  fog ?
  343.  2300  unknown
  344.  3000  unknown
  345.  3D3E  Editor configuration main block
  346.  4000  Definition of an Object
  347.  AFFF  Start of material list
  348.  
  349.  * Subchunks of AFFF - Start of material list
  350.  
  351.  - Not much is known as of yet, only one chunk can be defined
  352.  
  353.    id      Description
  354.  A000    Materials name
  355.  A010    unknown
  356.  A020    unknown
  357.  A030    unknown
  358.  A040    unknown
  359.  A041    unknown
  360.  A050    unknown
  361.  A052    unknown
  362.  A053    unknown
  363.  A100    unknown
  364.  A084    unknown
  365.  A087    unknown
  366.  
  367.  * A000 - material name
  368.  
  369.  - This chunk contains the name of the material which is an ASCIIZ string
  370.  
  371.  * Subchunks of 3D3E - Editor configuration
  372.  
  373.   id   Description
  374.  7001  Start of viewport indicator
  375.  7011  Viewport definition ( type 2 )
  376.  7012  Viewport definition ( type 1 )
  377.  7020  Viewport definition ( type 3 )
  378.  
  379.  The 3D3E chunk is a curious one because it contains a lot of redundant
  380.  data. ( or so it seems ) The most important chunk is 7020. this chunk
  381.  describes the 4 viewports wich are active in the editor. I assume that
  382.  U are using the 4 normal viewport layout, because I have not tested it
  383.  with other configurations. The editor confid will contain 5x chunk 7020
  384.  and 5x chunk 7011. only the first 4 7020 chunks are important for how
  385.  the viewports look like. I guess that the other chunks only give additional
  386.  info, but I am not sure. The things you are looking for in these chunks is
  387.  at byte: 6 & 7 ( as offset from the first 6 bytes chunk header and pointer )
  388.  these bytes ( unsigned int ) contain the info at to what view is used, with
  389.  the following id's:
  390.  
  391.   id    Description
  392.  0001   Top
  393.  0002   Bottom
  394.  0003   Left
  395.  0004   Right
  396.  0005   Front
  397.  0006   Back
  398.  0007   User
  399.  FFFF   Camera
  400.  0009   Light
  401.  0010   Disabled
  402.  
  403.  * Subchunks of 4000 - Object description Block
  404.  
  405.  - first item of Subchunk 4000 is an ASCIIZ string of the objects name.
  406.    ASCIIZ means a string of charakters ended by a zero.
  407.  
  408.  Remember an Object can be a Camera a Light or a mesh
  409.   id      Description
  410.  4010     unknown
  411.  4012     shadow ?
  412.  4100     Triangular Polygon List
  413.  4600     Light
  414.  4700     Camera
  415.  
  416.  * Subchunks of 4100 - Triangular Polygon List
  417.  
  418.   id      Description
  419.  4110     Vertex List
  420.  4110     unknown
  421.  4120     Face List
  422.  4150     Face smoothing group
  423.  4160     Translation Matrix
  424.  4165     Object visible/invisble
  425.  
  426.  * 4110 - Vertex List
  427.  
  428.  start end size type          name
  429.  0     1    2   unsigned int  Total vertices in object
  430.  2     5    4   float         X-value
  431.  6     9    4   float         Y-value
  432. 10    13    4   float         Z-value
  433.  
  434.  bytes 2..13 are repeated times the total amount of vertices in the object
  435.  
  436.  * 4111 - unknown
  437.  
  438.  start end size type          name
  439.  0     1    2   unsigned int  Total vertices in object ?
  440.  2     5    4   unsigned int  X-value
  441.  .     .    .    ..             ..
  442.  
  443.  bytes 2..13 are repeated for X-times as described by the first unsigned int
  444.  at the start of the record
  445.  
  446.  * 4120 - Face list
  447.  
  448.  start end size type          name
  449.  0     1    2   unsigned int  total polygons in object (numpoly)
  450.  
  451.  2     3    2   unsigned int  number of vertex A
  452.  4     5    2   unsigned int  number of vertex B
  453.  6     7    2   unsigned int  number of vertex C
  454.  8     9    2   unsigned int  a number which probably describes the order
  455.                               of the vertices. (1)
  456.  
  457.  repeats 'numpoly' times for each polygon.
  458.  
  459.  (1) this number is is a binary number which expands to 3 values.
  460.      for example 0x0006 would expand to 110 binary. The value should be
  461.      read as 1 1 0 .This value can be found in 3d-studio ascii files as
  462.      AB:1 BC:1 AC:0 .Which probably indicated the order of the vertices.
  463.      For example AB:1 would be a normal line from A to B. But AB:0 would
  464.      mean a line from B to A.
  465.  
  466.  * 4160 - Translation Matrix
  467.  
  468.    This structure describes a matrix for the object.
  469.    It is stored as a 3x4 matrix because it is assumed that the right most
  470.    column is 0,0,0,1
  471.  
  472.    start end size type  name
  473.    0     3    4   float  matrix 1,1
  474.    4     7    4   float  matrix 1,2
  475.    8    11    4   float  matrix 1,3
  476.   12    15    4   float  matrix 2,1
  477.   16    19    4   float  matrix 2,2
  478.   20    23    4   float  matrix 2,3
  479.   24    27    4   float  matrix 3,1
  480.   28    31    4   float  matrix 3,2
  481.   32    35    4   float  matrix 3,3
  482.   36    39    4   float  matrix 4,1
  483.   40    43    4   float  matrix 4,2
  484.   44    47    4   float  matrix 4,3
  485.  
  486.   * 4600 - Light
  487.  
  488.   start end size type   name
  489.   0      3    4  float  Light pos X
  490.   4      7    4  float  Light pos Y
  491.   8     11    4  float  Light pos Z
  492.  
  493.   after this structure check for more chunks.
  494.  
  495.   id      Description ( full description later )
  496.  0010     RGB color
  497.  0011     24 bit color
  498.  4610     Light is a Spot light
  499.  4620     Light is off/on ( Boolean )
  500.  
  501.  * 4610 - Spot Light
  502.  
  503.  start end size type   name
  504.   0     3    4  float  Target pos X
  505.   4     7    4  float  Target pos X
  506.   8    11    4  float  Target pos X
  507.  12    15    4  float  Hotspot
  508.  16    19    4  float  Falloff
  509.  
  510.  * 0010 - RGB Color
  511.  
  512.  start end size type   name
  513.   0     3   4   float  Red
  514.   4     7   4   float  Green
  515.   8    11   4   float  Blue
  516.  
  517.  * 0011 - RGB Color - 24 bit
  518.  
  519.  start end size type   name
  520.   0    1    1   byte   Red
  521.   1    1    1   byte   Green
  522.   2    2    1   byte   Blue
  523.  
  524.  * 4700 - Camera
  525.  
  526.  Describes the details of the camera in the scene
  527.  
  528.  start end size type   name
  529.   0     3   4   float  Camera pos X
  530.   4     7   4   float  Camera pos Y
  531.   8    11   4   float  Camera pos Z
  532.  12    15   4   float  Camera target X
  533.  16    19   4   float  Camera target X
  534.  20    23   4   float  Camera target X
  535.  24    27   4   float  Camera bank ( rotation angle )
  536.  28    31   4   float  Camera lens
  537.  
  538.  
  539.  * Keyframer chunk
  540.  
  541.   id         Description
  542.  B00A        unknown
  543.  7001        See first description of this chunk
  544.  B008        Frames
  545.  B009        unknown
  546.  B002        Start object description
  547.  
  548.  * B008 - Frame information
  549.  
  550.  simple structure describing frame info
  551.  
  552.  start end size type            name
  553.    0    3    4  unsigned long   start frame
  554.    4    7    4  unsigned long   end frame
  555.  
  556.  *B002 - Start of Object info
  557.  
  558.  Subhunks
  559.  
  560.   id     Description
  561.  B010    Name & Hierarchy
  562.  B011*   Name Dummy Object
  563.  B013    unknown
  564.  B014*   unknown
  565.  B015    unknown
  566.  B020    Objects pivot point ?
  567.  B021    unknown
  568.  B022    unknown
  569.  
  570.  * B010 - Name & Hierarchy descriptor
  571.  
  572.  start end  size type          name
  573.  0      ?    ?   ASCIIZ        Object name
  574.  ?      ?    ?   unsigned int  unknown
  575.  ?      ?    ?   unsigned int  unknown
  576.  ?      ?    ?   unsigned int  Hierarchy of Object
  577.  
  578.  The object hierarchy is a bit complex but works like this.
  579.  Each Object in the scene is given a number to identify its
  580.  order in the tree. Also each object is orddered in the 3ds
  581.  file as it would appear in the tree.
  582.  The root object is given the number -1 ( FFFF ).
  583.  As the file is read a counter of the object number is kept.
  584.  Is the counter increments the object are children of the
  585.  previous objects.But when the pattern is broken by a number
  586.  what will be less than the current counter the hierarchy returns
  587.  to that level.
  588.  
  589.  for example.
  590.  
  591.     object   hierarchy
  592.     name
  593.  
  594.         A      -1
  595.         B       0                 This example is taken
  596.         C       1                 from 50pman.3ds
  597.         D       2
  598.         E       1                 I would really reccomend
  599.         F       4                 having a look at one of the
  600.         G       5                 examples with the hierarchy
  601.         H       1                 numbers to help work it out.
  602.         I       7
  603.         J       8
  604.         K       0
  605.         L      10
  606.         M      11
  607.         N       0
  608.         O      13
  609.         P      14
  610.  
  611.  
  612.                            A
  613.          +-----------------+----------------+
  614.          B                 K                N
  615.     +----+----+            +                +
  616.     C    E    H            L                O
  617.     +    +    +            +                +
  618.     D    F    I            M                P
  619.          +    +
  620.          G    J
  621.  
  622.  Still not done with this chunk yet !
  623.  If the object name is $$$DUMMY then it is a dummy object
  624.  and therefore you should expect a few extra chunks.
  625.  
  626.  * B011 - Dummy objects name.
  627.  
  628.     Names a dummy object. ASCIIZ string.
  629.  
  630.  * B020 - Pivot Point ?
  631.  
  632.  The Objects pivot point. Not quite sure what the first five floats do yet
  633.  ( ideas ?).
  634.  
  635.  start end size type   name
  636.    0    3    4  float  unknown
  637.    4    7    4  float  unknown
  638.    8   11    4  float  unknown
  639.   12   16    4  float  unknown
  640.   16   19    4  float  unknown
  641.   20   23    4  float  unknown
  642.   24   27    4  float  Pivot Y
  643.   28   32    4  float  Pivot X
  644.  
  645.  
  646.  
  647.  AND NOW FOR THE SOURCE CODE:
  648.  
  649.  
  650.  
  651.  -----------------------------8=<  cut here  >=8-----------------------------
  652.  
  653.  
  654.  
  655.  
  656. /*----------------------------------------------------------------------------*\
  657.      This is a lib which reads 3d-studio binary files from version 3.0
  658.      and higher
  659.      (v1.05)
  660.      author: Martin van Velsen
  661.              ( and some great help by Gert van der Spoel )
  662.      email:  vvelsen@ronix.ptf.hro.nl
  663. \*----------------------------------------------------------------------------*/
  664. #ifndef __3DSBIN_H__
  665. #define __3DSBIN_h__
  666.  
  667. #include <stdio.h>
  668. #include <string.h>
  669. #include <stdlib.h>
  670. #include <conio.h>
  671. #include <dos.h>
  672.  
  673. //>------ tools
  674.  
  675. #define __DEBUG__          0
  676.  
  677. #define TRUE               0
  678. #define FALSE              1
  679.  
  680. //>------ Id Chunk
  681.  
  682. #define MAIN3DS       0x4D4D
  683.  
  684. //>------ Main Chunks
  685.  
  686. #define EDIT3DS       0x3D3D  // this is the start of the editor config
  687. #define KEYF3DS       0xB000  // this is the start of the keyframer config
  688.  
  689. //>------ sub defines of EDIT3DS
  690.  
  691. #define EDIT_MATERIAL 0xAFFF
  692. #define EDIT_CONFIG1  0x0100
  693. #define EDIT_CONFIG2  0x3E3D
  694. #define EDIT_VIEW_P1  0x7012
  695. #define EDIT_VIEW_P2  0x7011
  696. #define EDIT_VIEW_P3  0x7020
  697. #define EDIT_VIEW1    0x7001
  698. #define EDIT_BACKGR   0x1200
  699. #define EDIT_AMBIENT  0x2100
  700. #define EDIT_OBJECT   0x4000
  701.  
  702. #define EDIT_UNKNW01  0x1100
  703. #define EDIT_UNKNW02  0x1201
  704. #define EDIT_UNKNW03  0x1300
  705. #define EDIT_UNKNW04  0x1400
  706. #define EDIT_UNKNW05  0x1420
  707. #define EDIT_UNKNW06  0x1450
  708. #define EDIT_UNKNW07  0x1500
  709. #define EDIT_UNKNW08  0x2200
  710. #define EDIT_UNKNW09  0x2201
  711. #define EDIT_UNKNW10  0x2210
  712. #define EDIT_UNKNW11  0x2300
  713. #define EDIT_UNKNW12  0x2302 // new chunk type
  714. #define EDIT_UNKNW13  0x3000
  715. #define EDIT_UNKNW14  0xAFFF
  716.  
  717. //>------ sub defines of EDIT_MATERIAL
  718. #define MAT_NAME01    0xA000  //> includes name
  719. #define MAT_UNKNWN01  0xA010
  720. #define MAT_UNKNWN02  0xA020
  721. #define MAT_UNKNWN03  0xA030
  722. #define MAT_UNKNWN04  0xA040
  723. #define MAT_UNKNWN05  0xA041
  724. #define MAT_UNKNWN06  0xA050
  725. #define MAT_UNKNWN07  0xA052
  726. #define MAT_UNKNWN08  0xA053
  727. #define MAT_UNKNWN09  0xA100
  728. #define MAT_UNKNWN10  0xA084
  729. #define MAT_UNKNWN11  0xA087
  730.  
  731. //>------ sub defines of EDIT_OBJECT
  732.  
  733. #define OBJ_TRIMESH   0x4100
  734. #define OBJ_LIGHT     0x4600
  735. #define OBJ_CAMERA    0x4700
  736.  
  737. #define OBJ_UNKNWN01  0x4010
  738. #define OBJ_UNKNWN02  0x4012 //>>---- Could be shadow
  739.  
  740. //>------ sub defines of OBJ_CAMERA
  741. #define CAM_UNKNWN01  0x4710 // new chunk type
  742. #define CAM_UNKNWN02  0x4720 // new chunk type
  743.  
  744. //>------ sub defines of OBJ_LIGHT
  745. #define LIT_OFF       0x4620
  746. #define LIT_SPOT      0x4610
  747. #define LIT_UNKNWN01  0x465A
  748.  
  749. //>------ sub defines of OBJ_TRIMESH
  750. #define TRI_VERTEXL   0x4110
  751. #define TRI_FACEL2    0x4111 // unknown yet
  752. #define TRI_FACEL1    0x4120
  753. #define TRI_SMOOTH    0x4150
  754. #define TRI_TRANSL    0x4160
  755. #define TRI_VISIBLE   0x4165
  756.  
  757. //>>------ sub defs of KEYF3DS
  758.  
  759. #define KEYF_UNKNWN01 0xB009
  760. #define KEYF_UNKNWN02 0xB00A
  761. #define KEYF_FRAMES   0xB008
  762. #define KEYF_OBJDES   0xB002
  763.  
  764. //>>------  these define the different color chunk types
  765. #define COL_RGB  0x0010
  766. #define COL_TRU  0x0011
  767. #define COL_UNK  0x0013 // unknown
  768.  
  769. //>>------ defines for viewport chunks
  770.  
  771. #define TOP           0x0001
  772. #define BOTTOM        0x0002
  773. #define LEFT          0x0003
  774. #define RIGHT         0x0004
  775. #define FRONT         0x0005
  776. #define BACK          0x0006
  777. #define USER          0x0007
  778. #define CAMERA        0x0008 // 0xFFFF is the code read from file
  779. #define LIGHT         0x0009
  780. #define DISABLED      0x0010
  781. #define BOGUS         0x0011
  782.  
  783. //>------ global vars
  784.  
  785. char *viewports [11]={
  786.                       "Bogus",
  787.                       "Top",
  788.                       "Bottom",
  789.                       "Left",
  790.                       "Right",
  791.                       "Front",
  792.                       "Back",
  793.                       "User",
  794.                       "Camera",
  795.                       "Light",
  796.                       "Disabled"
  797.                      };
  798.  
  799. FILE *bin3ds;
  800. unsigned long current_chunk=0L;
  801. unsigned char views_read=0;
  802. unsigned int numb_faces=0,numb_vertices=0;
  803. char temp_name [100];
  804. float trans_mat [4][4]; // translation matrix for objects
  805.  
  806. #endif
  807.  
  808.  
  809.  
  810.  -----------------------------8=<  cut here  >=8-----------------------------
  811.  
  812.  
  813.  
  814. /*----------------------------------------------------------------------------*\
  815.      This is a lib which reads 3d-studio binary files from version 3.0
  816.      and higher
  817.      (v1.05)
  818.      author: Martin van Velsen
  819.              ( and some great help by Gert van der Spoel )
  820.      email:  vvelsen@ronix.ptf.hro.nl
  821. \*----------------------------------------------------------------------------*/
  822. #ifndef __3DSBIN_C__
  823. #define __3DSBIN_C__
  824.  
  825. #include "3ds_bin.h"
  826.  
  827. /*----------------------------------------------------------------------------*/
  828. unsigned char ReadChar (void)
  829. {
  830.  return (fgetc (bin3ds));
  831. }
  832. /*----------------------------------------------------------------------------*/
  833. unsigned int ReadInt (void)
  834. {
  835.  return (ReadChar () | (ReadChar () << 8));
  836. }
  837. /*----------------------------------------------------------------------------*/
  838. unsigned long ReadLong (void)
  839. {
  840.  unsigned long temp1,temp2;
  841.  
  842.  temp1=(ReadChar () | (ReadChar () << 8));
  843.  temp2=(ReadChar () | (ReadChar () << 8));
  844.  
  845.  return (temp1+(temp2*0x10000L));
  846. }
  847. /*----------------------------------------------------------------------------*/
  848. unsigned long ReadChunkPointer (void)
  849. {
  850.  return (ReadLong ());
  851. }
  852. /*----------------------------------------------------------------------------*/
  853. unsigned long GetChunkPointer (void)
  854. {
  855.  return (ftell (bin3ds)-2); // compensate for the already read Marker
  856. }
  857. /*----------------------------------------------------------------------------*/
  858. void ChangeChunkPointer (unsigned long temp_pointer)
  859. {
  860.  fseek (bin3ds,temp_pointer,SEEK_SET);
  861. }
  862. /*----------------------------------------------------------------------------*/
  863. int ReadName (void)
  864. {
  865.  unsigned int teller=0;
  866.  unsigned char letter;
  867.  
  868.  strcpy (temp_name,"Default name");
  869.  
  870.  letter=ReadChar ();
  871.  if (letter==0) return (-1); // dummy object
  872.  temp_name [teller]=letter;
  873.  teller++;
  874.  
  875.  do
  876.  {
  877.   letter=ReadChar ();
  878.   temp_name [teller]=letter;
  879.   teller++;
  880.  }
  881.  while ((letter!=0) && (teller<12));
  882.  
  883.  temp_name [teller-1]=0;
  884.  
  885.  #ifdef __DEBUG__
  886.   printf ("     Found name : %s\n",temp_name);
  887.  #endif
  888.  return (0);
  889. }
  890. /*----------------------------------------------------------------------------*/
  891. int ReadLongName (void)
  892. {
  893.  unsigned int teller=0;
  894.  unsigned char letter;
  895.  
  896.  strcpy (temp_name,"Default name");
  897.  
  898.  letter=ReadChar ();
  899.  if (letter==0) return (-1); // dummy object
  900.  temp_name [teller]=letter;
  901.  teller++;
  902.  
  903.  do
  904.  {
  905.   letter=ReadChar ();
  906.   temp_name [teller]=letter;
  907.   teller++;
  908.  }
  909.  while (letter!=0);
  910.  
  911.  temp_name [teller-1]=0;
  912.  
  913.  #ifdef __DEBUG__
  914.    printf ("Found name : %s\n",temp_name);
  915.  #endif
  916.  return (0);
  917. }
  918. /*----------------------------------------------------------------------------*/
  919. unsigned long ReadUnknownChunk (unsigned int chunk_id)
  920. {
  921.  unsigned long current_pointer;
  922.  unsigned long temp_pointer;
  923.  
  924.  chunk_id=chunk_id;
  925.  
  926.  current_pointer=GetChunkPointer ();
  927.  temp_pointer   =ReadChunkPointer ();
  928.  
  929.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  930.  return (temp_pointer);
  931. }
  932. /*----------------------------------------------------------------------------*/
  933. unsigned long ReadRGBColor (void)
  934. {
  935.  float rgb_val [3];
  936.  
  937.  for (int i=0;i<3;i++)
  938.   fread (&(rgb_val [i]),sizeof (float),1,bin3ds);
  939.  
  940.  #ifdef __DEBUG__
  941.  printf ("     Found Color (RGB) def of: R:%5.2f,G:%5.2f,B:%5.2f\n",
  942.           rgb_val [0],
  943.           rgb_val [1],
  944.           rgb_val [2]);
  945.  #endif
  946.  
  947.  return (12L);
  948. }
  949. /*----------------------------------------------------------------------------*/
  950. unsigned long ReadTrueColor (void)
  951. {
  952.  unsigned char true_c_val [3];
  953.  
  954.  for (int i=0;i<3;i++)
  955.   true_c_val [i]=ReadChar ();
  956.  
  957.  #ifdef __DEBUG__
  958.  printf ("     Found Color (24bit) def of: R:%d,G:%d,B:%d\n",
  959.           true_c_val [0],
  960.           true_c_val [1],
  961.           true_c_val [2]);
  962.  #endif
  963.  
  964.  return (3L);
  965. }
  966. /*----------------------------------------------------------------------------*/
  967. unsigned long ReadBooleanChunk (unsigned char *boolean)
  968. {
  969.  unsigned long current_pointer;
  970.  unsigned long temp_pointer;
  971.  
  972.  current_pointer=GetChunkPointer ();
  973.  temp_pointer   =ReadChunkPointer ();
  974.  
  975.  *boolean=ReadChar ();
  976.  
  977.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  978.  return (temp_pointer);
  979. }
  980. /*----------------------------------------------------------------------------*/
  981. unsigned long ReadSpotChunk (void)
  982. {
  983.  unsigned long current_pointer;
  984.  unsigned long temp_pointer;
  985.  float target [4];
  986.  float hotspot,falloff;
  987.  
  988.  current_pointer=GetChunkPointer ();
  989.  temp_pointer   =ReadChunkPointer ();
  990.  
  991.  fread (&(target [0]),sizeof (float),1,bin3ds);
  992.  fread (&(target [1]),sizeof (float),1,bin3ds);
  993.  fread (&(target [2]),sizeof (float),1,bin3ds);
  994.  fread (&hotspot,sizeof (float),1,bin3ds);
  995.  fread (&falloff,sizeof (float),1,bin3ds);
  996.  
  997.  #ifdef __DEBUG__
  998.  printf ("      The target of the spot is at: X:%5.2f Y:%5.2f Y:%5.2f\n",
  999.           target [0],
  1000.           target [1],
  1001.           target [2]);
  1002.  printf ("      The hotspot of this light is : %5.2f\n",hotspot);
  1003.  printf ("      The falloff of this light is : %5.2f\n",falloff);
  1004.  #endif
  1005.  
  1006.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1007.  return (temp_pointer);
  1008. }
  1009. /*----------------------------------------------------------------------------*/
  1010. unsigned long ReadLightChunk (void)
  1011. {
  1012.  unsigned char end_found=FALSE,boolean;
  1013.  unsigned int temp_int;
  1014.  unsigned long current_pointer;
  1015.  unsigned long temp_pointer;
  1016.  unsigned long tellertje=6L; // 2 id + 4 pointer
  1017.  float light_coors [3];
  1018.  
  1019.  current_pointer=GetChunkPointer ();
  1020.  temp_pointer   =ReadChunkPointer ();
  1021.  
  1022.  fread (&(light_coors [0]),sizeof (float),1,bin3ds);
  1023.  fread (&(light_coors [1]),sizeof (float),1,bin3ds);
  1024.  fread (&(light_coors [2]),sizeof (float),1,bin3ds);
  1025.  
  1026.  #ifdef __DEBUG__
  1027.  printf ("     Found light at coordinates: X: %5.2f, Y: %5.2f,Z: %5.2f\n",
  1028.           light_coors [0],
  1029.           light_coors [1],
  1030.           light_coors [2]);
  1031.  #endif
  1032.  
  1033.  while (end_found==FALSE)
  1034.  {
  1035.    temp_int=ReadInt ();
  1036.  
  1037.        switch (temp_int)
  1038.        {
  1039.         case LIT_UNKNWN01 :
  1040.                            #ifdef __DEBUG__
  1041.                            printf (">>>>> Found Light unknown chunk id of %0X\n",LIT_UNKNWN01);
  1042.                            #endif
  1043.                            tellertje+=ReadUnknownChunk (LIT_UNKNWN01);
  1044.                            break;
  1045.         case LIT_OFF      :
  1046.                            #ifdef __DEBUG__
  1047.                            printf (">>>>> Light is (on/off) chunk: %0X\n",LIT_OFF);
  1048.                            #endif
  1049.                            tellertje+=ReadBooleanChunk (&boolean);
  1050.                            #ifdef __DEBUG__
  1051.                            if (boolean==TRUE)
  1052.                              printf ("      Light is on\n");
  1053.                            else
  1054.                              printf ("      Light is off\n");
  1055.                            #endif
  1056.                            break;
  1057.         case LIT_SPOT     :
  1058.                            #ifdef __DEBUG__
  1059.                            printf (">>>>> Light is SpotLight: %0X\n",TRI_VERTEXL);
  1060.                            #endif
  1061.                            tellertje+=ReadSpotChunk ();
  1062.                            break;
  1063.         case COL_RGB      :
  1064.                            #ifdef __DEBUG__
  1065.                            printf (">>>>> Found Color def (RGB) chunk id of %0X\n",temp_int);
  1066.                            #endif
  1067.                            tellertje+=ReadRGBColor ();
  1068.                            break;
  1069.         case COL_TRU      :
  1070.                            #ifdef __DEBUG__
  1071.                            printf (">>>>> Found Color def (24bit) chunk id of %0X\n",temp_int);
  1072.                            #endif
  1073.                            tellertje+=ReadTrueColor ();
  1074.                            break;
  1075.         default           :break;
  1076.        }
  1077.  
  1078.    tellertje+=2;
  1079.    if (tellertje>=temp_pointer)
  1080.      end_found=TRUE;
  1081.  }
  1082.  
  1083.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1084.  return (temp_pointer);
  1085. }
  1086. /*----------------------------------------------------------------------------*/
  1087. unsigned long ReadCameraChunk (void)
  1088. {
  1089.  unsigned long current_pointer;
  1090.  unsigned long temp_pointer;
  1091.  float camera_eye [3];
  1092.  float camera_focus [3];
  1093.  float rotation,lens;
  1094.  
  1095.  current_pointer=GetChunkPointer ();
  1096.  temp_pointer   =ReadChunkPointer ();
  1097.  
  1098.  fread (&(camera_eye [0]),sizeof (float),1,bin3ds);
  1099.  fread (&(camera_eye [1]),sizeof (float),1,bin3ds);
  1100.  fread (&(camera_eye [2]),sizeof (float),1,bin3ds);
  1101.  
  1102.  #ifdef __DEBUG__
  1103.  printf ("     Found Camera viewpoint at coordinates: X: %5.2f, Y: %5.2f,Z: %5.2f\n",
  1104.           camera_eye [0],
  1105.           camera_eye [1],
  1106.           camera_eye [2]);
  1107.  #endif
  1108.  
  1109.  fread (&(camera_focus [0]),sizeof (float),1,bin3ds);
  1110.  fread (&(camera_focus [1]),sizeof (float),1,bin3ds);
  1111.  fread (&(camera_focus [2]),sizeof (float),1,bin3ds);
  1112.  
  1113.  #ifdef __DEBUG__
  1114.  printf ("     Found Camera focus coors at coordinates: X: %5.2f, Y: %5.2f,Z: %5.2f\n",
  1115.           camera_focus [0],
  1116.           camera_focus [1],
  1117.           camera_focus [2]);
  1118.  #endif
  1119.  
  1120.  fread (&rotation,sizeof (float),1,bin3ds);
  1121.  fread (&lens,sizeof (float),1,bin3ds);
  1122.  #ifdef __DEBUG__
  1123.  printf ("     Rotation of camera is:  %5.4f\n",rotation);
  1124.  printf ("     Lens in used camera is: %5.4fmm\n",lens);
  1125.  #endif
  1126.  
  1127.  if ((temp_pointer-38)>0) // this means more chunks are to follow
  1128.  {
  1129.   #ifdef __DEBUG__
  1130.   printf ("     **** found extra cam chunks ****\n");
  1131.   #endif
  1132.   if (ReadInt ()==CAM_UNKNWN01)
  1133.   {
  1134.    #ifdef __DEBUG__
  1135.    printf ("     **** Found cam 1 type ch ****\n");
  1136.    #endif
  1137.    ReadUnknownChunk (CAM_UNKNWN01);
  1138.   }
  1139.   if (ReadInt ()==CAM_UNKNWN02)
  1140.   {
  1141.    #ifdef __DEBUG__
  1142.    printf ("     **** Found cam 2 type ch ****\n");
  1143.    #endif
  1144.    ReadUnknownChunk (CAM_UNKNWN02);
  1145.   }
  1146.  }
  1147.  
  1148.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1149.  return (temp_pointer);
  1150. }
  1151. /*----------------------------------------------------------------------------*/
  1152. unsigned long ReadVerticesChunk (void)
  1153. {
  1154.  unsigned long current_pointer;
  1155.  unsigned long temp_pointer;
  1156.  float vertices [3]; // x,y,z
  1157.  unsigned int numb_v;
  1158.  
  1159.  current_pointer=GetChunkPointer ();
  1160.  temp_pointer   =ReadChunkPointer ();
  1161.  numb_vertices  =ReadInt ();
  1162.  
  1163.  #ifdef __DEBUG__
  1164.  printf ("      Found (%d) number of vertices\n",numb_vertices);
  1165.  #endif
  1166.  
  1167.  for (int i=0;i<numb_vertices;i++)
  1168.  {
  1169.   fread (&(vertices [0]),sizeof (float),1,bin3ds);
  1170.   fread (&(vertices [1]),sizeof (float),1,bin3ds);
  1171.   fread (&(vertices [2]),sizeof (float),1,bin3ds);
  1172.  
  1173.   #ifdef __DEBUG__
  1174.   printf ("      Vertex nr%4d: X: %5.2f  Y: %5.2f  Z:%5.2f\n",
  1175.            i,
  1176.            vertices [0],
  1177.            vertices [1],
  1178.            vertices [2]);
  1179.   #endif
  1180.  }
  1181.  
  1182.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1183.  return (temp_pointer);
  1184. }
  1185. /*----------------------------------------------------------------------------*/ unsigned long current_pointer;
  1186. unsigned long ReadSmoothingChunk ()
  1187. {
  1188.  unsigned long current_pointer;
  1189.  unsigned long temp_pointer;
  1190.  unsigned long smoothing;
  1191.  
  1192.  current_pointer=GetChunkPointer ();
  1193.  temp_pointer   =ReadChunkPointer ();
  1194.  
  1195.  for (int i=0;i<numb_faces;i++)
  1196.  {
  1197.   smoothing=ReadLong();
  1198.   smoothing=smoothing; // compiler warnig depressor *>:)
  1199.   #ifdef __DEBUG__
  1200.   printf ("      The smoothing group for face [%5d] is %d\n",i,smoothing);
  1201.   #endif
  1202.  }
  1203.  
  1204.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1205.  return (temp_pointer);
  1206. }
  1207. /*----------------------------------------------------------------------------*/
  1208. unsigned long ReadFacesChunk (void)
  1209. {
  1210.  unsigned long current_pointer;
  1211.  unsigned long temp_pointer;
  1212.  unsigned int temp_diff;
  1213.  unsigned int faces [6]; // a,b,c,Diff (Diff= AB: BC: CA: )
  1214.  
  1215.  current_pointer=GetChunkPointer ();
  1216.  temp_pointer   =ReadChunkPointer ();
  1217.  numb_faces     =ReadInt ();
  1218.  #ifdef __DEBUG__
  1219.  printf ("      Found (%d) number of faces\n",numb_faces);
  1220.  #endif
  1221.  
  1222.  for (int i=0;i<numb_faces;i++)
  1223.  {
  1224.   faces [0]=ReadInt ();
  1225.   faces [1]=ReadInt ();
  1226.   faces [2]=ReadInt ();
  1227.   temp_diff=ReadInt () & 0x000F;
  1228.   faces [3]=(temp_diff & 0x0004) >> 2;
  1229.   faces [4]=(temp_diff & 0x0002) >> 1;
  1230.   faces [5]=(temp_diff & 0x0001);
  1231.  
  1232.   #ifdef __DEBUG__
  1233.   printf ("      Face nr:%d, A: %d  B: %d  C:%d , AB:%d  BC:%d  CA:%d\n",
  1234.            i,
  1235.            faces [0],
  1236.            faces [1],
  1237.            faces [2],
  1238.            faces [3],
  1239.            faces [4],
  1240.            faces [5]);
  1241.   #endif
  1242.  }
  1243.  
  1244.  if (ReadInt ()==TRI_SMOOTH)
  1245.   ReadSmoothingChunk ();
  1246.  #ifdef __DEBUG__
  1247.  else
  1248.   printf ("      No smoothing groups found, assuming autosmooth\n");
  1249.  #endif
  1250.  
  1251.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1252.  return (temp_pointer);
  1253. }
  1254. /*----------------------------------------------------------------------------*/
  1255. unsigned long ReadTranslationChunk (void)
  1256. {
  1257.  unsigned long current_pointer;
  1258.  unsigned long temp_pointer;
  1259.  current_pointer=GetChunkPointer ();
  1260.  temp_pointer   =ReadChunkPointer ();
  1261.  
  1262.  for (int j=0;j<4;j++)
  1263.  {
  1264.    for (int i=0;i<3;i++)
  1265.     fread (&(trans_mat [j][i]),sizeof (float),1,bin3ds);
  1266.  }
  1267.  
  1268.  trans_mat [0][3]=0;
  1269.  trans_mat [1][3]=0;
  1270.  trans_mat [2][3]=0;
  1271.  trans_mat [3][3]=1;
  1272.  
  1273.  #ifdef __DEBUG__
  1274.  printf ("     The translation matrix is:\n");
  1275.  for (int i=0;i<4;i++)
  1276.      printf ("      | %5.2f %5.2f %5.2f %5.2f |\n",
  1277.               trans_mat [i][0],
  1278.               trans_mat [i][1],
  1279.               trans_mat [i][2],
  1280.               trans_mat [i][3]);
  1281.  #endif
  1282.  
  1283.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1284.  return (temp_pointer);
  1285. }
  1286. /*----------------------------------------------------------------------------*/
  1287. unsigned long ReadObjChunk (void)
  1288. {
  1289.  unsigned char end_found=FALSE,boolean=TRUE;
  1290.  unsigned int temp_int;
  1291.  unsigned long current_pointer;
  1292.  unsigned long temp_pointer;
  1293.  unsigned long tellertje=6L; // 2 id + 4 pointer
  1294.  
  1295.  current_pointer=GetChunkPointer ();
  1296.  temp_pointer   =ReadChunkPointer ();
  1297.  
  1298.  while (end_found==FALSE)
  1299.  {
  1300.    temp_int=ReadInt ();
  1301.  
  1302.        switch (temp_int)
  1303.        {
  1304.         case TRI_VERTEXL :
  1305.                           #ifdef __DEBUG__
  1306.                           printf (">>>>> Found Object vertices chunk id of %0X\n",temp_int);
  1307.                           #endif
  1308.                           tellertje+=ReadVerticesChunk ();
  1309.                           break;
  1310.         case TRI_FACEL1  :
  1311.                           #ifdef __DEBUG__
  1312.                           printf (">>>>> Found Object faces (1) chunk id of %0X\n",temp_int);
  1313.                           #endif
  1314.                           tellertje+=ReadFacesChunk ();
  1315.                           break;
  1316.         case TRI_FACEL2  :
  1317.                           #ifdef __DEBUG__
  1318.                           printf (">>>>> Found Object faces (2) chunk id of %0X\n",temp_int);
  1319.                           #endif
  1320.                           tellertje+=ReadUnknownChunk (temp_int);
  1321.                           break;
  1322.         case TRI_TRANSL  :
  1323.                           #ifdef __DEBUG__
  1324.                           printf (">>>>> Found Object translation chunk id of %0X\n",temp_int);
  1325.                           #endif
  1326.                           tellertje+=ReadTranslationChunk ();
  1327.                           break;
  1328.         case TRI_VISIBLE :
  1329.                           #ifdef __DEBUG__
  1330.                           printf (">>>>> Found Object vis/invis chunk id of %0X\n",temp_int);
  1331.                           #endif
  1332.                           tellertje+=ReadBooleanChunk (&boolean);
  1333.  
  1334.                           #ifdef __DEBUG__
  1335.                           if (boolean==TRUE)
  1336.                              printf ("      Object is (visible)\n");
  1337.                           else
  1338.                              printf ("      Object is (not visible)\n");
  1339.                           #endif
  1340.                           break;
  1341.         default:          break;
  1342.        }
  1343.  
  1344.    tellertje+=2;
  1345.    if (tellertje>=temp_pointer)
  1346.      end_found=TRUE;
  1347.  }
  1348.  
  1349.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1350.  return (temp_pointer);
  1351. }
  1352. /*----------------------------------------------------------------------------*/
  1353. unsigned long ReadObjectChunk (void)
  1354. {
  1355.  unsigned char end_found=FALSE;
  1356.  unsigned int temp_int;
  1357.  unsigned long current_pointer;
  1358.  unsigned long temp_pointer;
  1359.  unsigned long tellertje=6L; // 2 id + 4 pointer
  1360.  
  1361.  current_pointer=GetChunkPointer ();
  1362.  temp_pointer   =ReadChunkPointer ();
  1363.  
  1364.  if (ReadName ()==-1)
  1365.  {
  1366.   #ifdef __DEBUG__
  1367.   printf (">>>>* Dummy Object found\n");
  1368.   #endif
  1369.  }
  1370.  
  1371.  while (end_found==FALSE)
  1372.  {
  1373.    temp_int=ReadInt ();
  1374.  
  1375.        switch (temp_int)
  1376.        {
  1377.         case OBJ_UNKNWN01:tellertje+=ReadUnknownChunk (OBJ_UNKNWN01);break;
  1378.         case OBJ_UNKNWN02:tellertje+=ReadUnknownChunk (OBJ_UNKNWN02);break;
  1379.         case OBJ_TRIMESH :
  1380.                           #ifdef __DEBUG__
  1381.                           printf (">>>> Found Obj/Mesh chunk id of %0X\n",OBJ_TRIMESH);
  1382.                           #endif
  1383.                           tellertje+=ReadObjChunk ();
  1384.                           break;
  1385.         case OBJ_LIGHT   :
  1386.                           #ifdef __DEBUG__
  1387.                           printf (">>>> Found Light chunk id of %0X\n",OBJ_LIGHT);
  1388.                           #endif
  1389.                           tellertje+=ReadLightChunk ();
  1390.                           break;
  1391.         case OBJ_CAMERA  :
  1392.                           #ifdef __DEBUG__
  1393.                           printf (">>>> Found Camera chunk id of %0X\n",OBJ_CAMERA);
  1394.                           #endif
  1395.                           tellertje+=ReadCameraChunk ();
  1396.                           break;
  1397.         default:          break;
  1398.        }
  1399.  
  1400.    tellertje+=2;
  1401.    if (tellertje>=temp_pointer)
  1402.      end_found=TRUE;
  1403.  }
  1404.  
  1405.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1406.  return (temp_pointer);
  1407. }
  1408. /*----------------------------------------------------------------------------*/
  1409. unsigned long ReadBackgrChunk (void)
  1410. {
  1411.  unsigned char end_found=FALSE;
  1412.  unsigned int temp_int;
  1413.  unsigned long current_pointer;
  1414.  unsigned long temp_pointer;
  1415.  unsigned long tellertje=6L; // 2 id + 4 pointer
  1416.  
  1417.  current_pointer=GetChunkPointer ();
  1418.  temp_pointer   =ReadChunkPointer ();
  1419.  
  1420.  while (end_found==FALSE)
  1421.  {
  1422.    temp_int=ReadInt ();
  1423.  
  1424.        switch (temp_int)
  1425.        {
  1426.         case COL_RGB :
  1427.                       #ifdef __DEBUG__
  1428.                       printf (">> Found Color def (RGB) chunk id of %0X\n",temp_int);
  1429.                       #endif
  1430.                       tellertje+=ReadRGBColor ();
  1431.                       break;
  1432.         case COL_TRU :
  1433.                       #ifdef __DEBUG__
  1434.                       printf (">> Found Color def (24bit) chunk id of %0X\n",temp_int);
  1435.                       #endif
  1436.                       tellertje+=ReadTrueColor ();
  1437.                       break;
  1438.         default:      break;
  1439.        }
  1440.  
  1441.    tellertje+=2;
  1442.    if (tellertje>=temp_pointer)
  1443.      end_found=TRUE;
  1444.  }
  1445.  
  1446.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1447.  return (temp_pointer);
  1448. }
  1449. /*----------------------------------------------------------------------------*/
  1450. unsigned long ReadAmbientChunk (void)
  1451. {
  1452.  unsigned char end_found=FALSE;
  1453.  unsigned int temp_int;
  1454.  unsigned long current_pointer;
  1455.  unsigned long temp_pointer;
  1456.  unsigned long tellertje=6L; // 2 id + 4 pointer
  1457.  
  1458.  current_pointer=GetChunkPointer ();
  1459.  temp_pointer   =ReadChunkPointer ();
  1460.  
  1461.  while (end_found==FALSE)
  1462.  {
  1463.    temp_int=ReadInt ();
  1464.  
  1465.        switch (temp_int)
  1466.        {
  1467.         case COL_RGB :
  1468.                       #ifdef __DEBUG__
  1469.                       printf (">>>> Found Color def (RGB) chunk id of %0X\n",temp_int);
  1470.                       #endif
  1471.                       tellertje+=ReadRGBColor ();
  1472.                       break;
  1473.         case COL_TRU :
  1474.                       #ifdef __DEBUG__
  1475.                       printf (">>>> Found Color def (24bit) chunk id of %0X\n",temp_int);
  1476.                       #endif
  1477.                       tellertje+=ReadTrueColor ();
  1478.                       break;
  1479.         default:      break;
  1480.        }
  1481.  
  1482.    tellertje+=2;
  1483.    if (tellertje>=temp_pointer)
  1484.      end_found=TRUE;
  1485.  }
  1486.  
  1487.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1488.  return (temp_pointer);
  1489. }
  1490. /*----------------------------------------------------------------------------*/
  1491. unsigned long FindCameraChunk (void)
  1492. {
  1493.  long temp_pointer=0L;
  1494.  
  1495.  for (int i=0;i<12;i++)
  1496.   ReadInt ();
  1497.  
  1498.  temp_pointer=11L;
  1499.  temp_pointer=ReadName ();
  1500.  
  1501.  #ifdef __DEBUG__
  1502.  if (temp_pointer==-1)
  1503.    printf (">>>>* No Camera name found\n");
  1504.  #endif
  1505.  
  1506.  return (temp_pointer);
  1507. }
  1508. /*----------------------------------------------------------------------------*/
  1509. unsigned long ReadViewPortChunk (void)
  1510. {
  1511.  unsigned long current_pointer;
  1512.  unsigned long temp_pointer;
  1513.  unsigned int port,attribs;
  1514.  
  1515.  views_read++;
  1516.  
  1517.  current_pointer=GetChunkPointer ();
  1518.  temp_pointer   =ReadChunkPointer ();
  1519.  
  1520.  attribs=ReadInt ();
  1521.  if (attribs==3)
  1522.  {
  1523.   #ifdef __DEBUG__
  1524.   printf ("<Snap> active in viewport\n");
  1525.   #endif
  1526.  }
  1527.  if (attribs==5)
  1528.  {
  1529.   #ifdef __DEBUG__
  1530.   printf ("<Grid> active in viewport\n");
  1531.   #endif
  1532.  }
  1533.  
  1534.  for (int i=1;i<6;i++) ReadInt (); // read 5 ints to get to the viewport
  1535.  
  1536.  port=ReadInt ();
  1537.  if ((port==0xFFFF) || (port==0))
  1538.  {
  1539.    FindCameraChunk ();
  1540.    port=CAMERA;
  1541.  }
  1542.  
  1543.  #ifdef __DEBUG__
  1544.  printf ("Reading [%s] information with id:%d\n",viewports [port],port);
  1545.  #endif
  1546.  
  1547.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1548.  return (temp_pointer);
  1549. }
  1550. /*----------------------------------------------------------------------------*/
  1551. unsigned long ReadViewChunk (void)
  1552. {
  1553.  unsigned char end_found=FALSE;
  1554.  unsigned int temp_int;
  1555.  unsigned long current_pointer;
  1556.  unsigned long temp_pointer;
  1557.  unsigned long tellertje=6L;
  1558.  
  1559.  current_pointer=GetChunkPointer ();
  1560.  temp_pointer   =ReadChunkPointer ();
  1561.  
  1562.  while (end_found==FALSE)
  1563.  {
  1564.    temp_int=ReadInt ();
  1565.  
  1566.        switch (temp_int)
  1567.        {
  1568.         case EDIT_VIEW_P1 :
  1569.                            #ifdef __DEBUG__
  1570.                            printf (">>>> Found Viewport1 chunk id of %0X\n",temp_int);
  1571.                            #endif
  1572.                            tellertje+=ReadViewPortChunk ();
  1573.                            break;
  1574.         case EDIT_VIEW_P2 :
  1575.                            #ifdef __DEBUG__
  1576.                            printf (">>>> Found Viewport2 (bogus) chunk id of %0X\n",temp_int);
  1577.                            #endif
  1578.                            tellertje+=ReadUnknownChunk (EDIT_VIEW_P2);
  1579.                            break;
  1580.        case EDIT_VIEW_P3 :
  1581.                            #ifdef __DEBUG__
  1582.                            printf (">>>> Found Viewport chunk id of %0X\n",temp_int);
  1583.                            #endif
  1584.                            tellertje+=ReadViewPortChunk ();
  1585.                            break;
  1586.         default           :break;
  1587.        }
  1588.  
  1589.    tellertje+=2;
  1590.    if (tellertje>=temp_pointer)
  1591.      end_found=TRUE;
  1592.  
  1593.    if (views_read>3)
  1594.      end_found=TRUE;
  1595.  }
  1596.  
  1597.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1598.  return (temp_pointer);
  1599. }
  1600. /*----------------------------------------------------------------------------*/
  1601. unsigned long ReadMatDefChunk (void)
  1602. {
  1603.  unsigned long current_pointer;
  1604.  unsigned long temp_pointer;
  1605.  
  1606.  current_pointer=GetChunkPointer ();
  1607.  temp_pointer   =ReadChunkPointer ();
  1608.  
  1609.  if (ReadLongName ()==-1)
  1610.  {
  1611.    #ifdef __DEBUG__
  1612.    printf (">>>>* No Material name found\n");
  1613.    #endif
  1614.  }
  1615.  
  1616.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1617.  return (temp_pointer);
  1618. }
  1619. /*----------------------------------------------------------------------------*/
  1620. unsigned long ReadMaterialChunk (void)
  1621. {
  1622.  unsigned char end_found=FALSE;
  1623.  unsigned int temp_int;
  1624.  unsigned long current_pointer;
  1625.  unsigned long temp_pointer;
  1626.  unsigned long tellertje=6L;
  1627.  
  1628.  current_pointer=GetChunkPointer ();
  1629.  temp_pointer   =ReadChunkPointer ();
  1630.  
  1631.  while (end_found==FALSE)
  1632.  {
  1633.    temp_int=ReadInt ();
  1634.  
  1635.        switch (temp_int)
  1636.        {
  1637.         case MAT_UNKNWN01:tellertje+=ReadUnknownChunk (temp_int);break;
  1638.         case MAT_UNKNWN02:tellertje+=ReadUnknownChunk (temp_int);break;
  1639.         case MAT_UNKNWN03:tellertje+=ReadUnknownChunk (temp_int);break;
  1640.         case MAT_UNKNWN04:tellertje+=ReadUnknownChunk (temp_int);break;
  1641.         case MAT_UNKNWN05:tellertje+=ReadUnknownChunk (temp_int);break;
  1642.         case MAT_UNKNWN06:tellertje+=ReadUnknownChunk (temp_int);break;
  1643.         case MAT_UNKNWN07:tellertje+=ReadUnknownChunk (temp_int);break;
  1644.         case MAT_UNKNWN08:tellertje+=ReadUnknownChunk (temp_int);break;
  1645.         case MAT_UNKNWN09:tellertje+=ReadUnknownChunk (temp_int);break;
  1646.         case MAT_UNKNWN10:tellertje+=ReadUnknownChunk (temp_int);break;
  1647.         case MAT_UNKNWN11:tellertje+=ReadUnknownChunk (temp_int);break;
  1648.         case MAT_NAME01  :
  1649.                           #ifdef __DEBUG__
  1650.                           printf (">>>> Found Material def chunk id of %0X\n",temp_int);
  1651.                           #endif
  1652.                           tellertje+=ReadMatDefChunk ();
  1653.                           break;
  1654.         default:break;
  1655.        }
  1656.  
  1657.    tellertje+=2;
  1658.    if (tellertje>=temp_pointer)
  1659.      end_found=TRUE;
  1660.  }
  1661.  
  1662.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1663.  return (temp_pointer);
  1664. }
  1665. /*----------------------------------------------------------------------------*/
  1666. unsigned long ReadEditChunk (void)
  1667. {
  1668.  unsigned char end_found=FALSE;
  1669.  unsigned int temp_int;
  1670.  unsigned long current_pointer;
  1671.  unsigned long temp_pointer;
  1672.  unsigned long tellertje=6L;
  1673.  
  1674.  current_pointer=GetChunkPointer ();
  1675.  temp_pointer   =ReadChunkPointer ();
  1676.  
  1677.  while (end_found==FALSE)
  1678.  {
  1679.    temp_int=ReadInt ();
  1680.  
  1681.        switch (temp_int)
  1682.        {
  1683.         case EDIT_UNKNW01:tellertje+=ReadUnknownChunk (EDIT_UNKNW01);break;
  1684.         case EDIT_UNKNW02:tellertje+=ReadUnknownChunk (EDIT_UNKNW02);break;
  1685.         case EDIT_UNKNW03:tellertje+=ReadUnknownChunk (EDIT_UNKNW03);break;
  1686.         case EDIT_UNKNW04:tellertje+=ReadUnknownChunk (EDIT_UNKNW04);break;
  1687.         case EDIT_UNKNW05:tellertje+=ReadUnknownChunk (EDIT_UNKNW05);break;
  1688.         case EDIT_UNKNW06:tellertje+=ReadUnknownChunk (EDIT_UNKNW06);break;
  1689.         case EDIT_UNKNW07:tellertje+=ReadUnknownChunk (EDIT_UNKNW07);break;
  1690.         case EDIT_UNKNW08:tellertje+=ReadUnknownChunk (EDIT_UNKNW08);break;
  1691.         case EDIT_UNKNW09:tellertje+=ReadUnknownChunk (EDIT_UNKNW09);break;
  1692.         case EDIT_UNKNW10:tellertje+=ReadUnknownChunk (EDIT_UNKNW10);break;
  1693.         case EDIT_UNKNW11:tellertje+=ReadUnknownChunk (EDIT_UNKNW11);break;
  1694.         case EDIT_UNKNW12:tellertje+=ReadUnknownChunk (EDIT_UNKNW12);break;
  1695.         case EDIT_UNKNW13:tellertje+=ReadUnknownChunk (EDIT_UNKNW13);break;
  1696.  
  1697.         case EDIT_MATERIAL :
  1698.                             #ifdef __DEBUG__
  1699.                             printf (">>> Found Materials chunk id of %0X\n",temp_int);
  1700.                             #endif
  1701.                             tellertje+=ReadMaterialChunk ();
  1702.                             break;
  1703.         case EDIT_VIEW1    :
  1704.                             #ifdef __DEBUG__
  1705.                             printf (">>> Found View main def chunk id of %0X\n",temp_int);
  1706.                             #endif
  1707.                             tellertje+=ReadViewChunk ();
  1708.                             break;
  1709.         case EDIT_BACKGR   :
  1710.                             #ifdef __DEBUG__
  1711.                             printf (">>> Found Backgr chunk id of %0X\n",temp_int);
  1712.                             #endif
  1713.                             tellertje+=ReadBackgrChunk ();
  1714.                             break;
  1715.         case EDIT_AMBIENT  :
  1716.                             #ifdef __DEBUG__
  1717.                             printf (">>> Found Ambient chunk id of %0X\n",temp_int);
  1718.                             #endif
  1719.                             tellertje+=ReadAmbientChunk ();
  1720.                             break;
  1721.         case EDIT_OBJECT   :
  1722.                             #ifdef __DEBUG__
  1723.                             printf (">>> Found Object chunk id of %0X\n",temp_int);
  1724.                             #endif
  1725.                             tellertje+=ReadObjectChunk ();
  1726.                             break;
  1727.         default:            break;
  1728.        }
  1729.  
  1730.    tellertje+=2;
  1731.    if (tellertje>=temp_pointer)
  1732.      end_found=TRUE;
  1733.  }
  1734.  
  1735.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1736.  return (temp_pointer);
  1737. }
  1738. /*----------------------------------------------------------------------------*/
  1739. unsigned long ReadKeyfChunk (void)
  1740. {
  1741.  unsigned char end_found=FALSE;
  1742.  unsigned int temp_int;
  1743.  unsigned long current_pointer;
  1744.  unsigned long temp_pointer;
  1745.  unsigned long tellertje=6L;
  1746.  
  1747.  current_pointer=GetChunkPointer ();
  1748.  temp_pointer   =ReadChunkPointer ();
  1749.  
  1750.  while (end_found==FALSE)
  1751.  {
  1752.    temp_int=ReadInt ();
  1753.  
  1754.        switch (temp_int)
  1755.        {
  1756.         case KEYF_UNKNWN01 :tellertje+=ReadUnknownChunk (temp_int);break;
  1757.         case KEYF_UNKNWN02 :tellertje+=ReadUnknownChunk (temp_int);break;
  1758.         case KEYF_FRAMES   :
  1759.                             #ifdef __DEBUG__
  1760.                             printf (">>> Found Keyframer frames chunk id of %0X\n",temp_int);
  1761.                             #endif
  1762.                             tellertje+=ReadUnknownChunk (temp_int);
  1763.                             break;
  1764.         case KEYF_OBJDES   :
  1765.                             #ifdef __DEBUG__
  1766.                             printf (">>> Found Keyframer object description chunk id of %0X\n",temp_int);
  1767.                             #endif
  1768.                             tellertje+=ReadUnknownChunk (temp_int);
  1769.                             break;
  1770.         case EDIT_VIEW1    :
  1771.                             #ifdef __DEBUG__
  1772.                             printf (">>> Found View main def chunk id of %0X\n",temp_int);
  1773.                             #endif
  1774.                             tellertje+=ReadViewChunk ();
  1775.                             break;
  1776.         default:            break;
  1777.        }
  1778.  
  1779.    tellertje+=2;
  1780.    if (tellertje>=temp_pointer)
  1781.      end_found=TRUE;
  1782.  }
  1783.  
  1784.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1785.  return (temp_pointer);
  1786. }
  1787. /*----------------------------------------------------------------------------*/
  1788. unsigned long ReadMainChunk (void)
  1789. {
  1790.  unsigned char end_found=FALSE;
  1791.  unsigned int temp_int;
  1792.  unsigned long current_pointer;
  1793.  unsigned long temp_pointer;
  1794.  unsigned long tellertje=6L;
  1795.  
  1796.  current_pointer=GetChunkPointer ();
  1797.  temp_pointer   =ReadChunkPointer ();
  1798.  
  1799.  while (end_found==FALSE)
  1800.  {
  1801.    temp_int=ReadInt ();
  1802.  
  1803.        switch (temp_int)
  1804.        {
  1805.         case KEYF3DS :
  1806.                       #ifdef __DEBUG__
  1807.                       printf (">> Found *Keyframer* chunk id of %0X\n",KEYF3DS);
  1808.                       #endif
  1809.                       tellertje+=ReadKeyfChunk ();
  1810.                       break;
  1811.         case EDIT3DS :
  1812.                       #ifdef __DEBUG__
  1813.                       printf (">> Found *Editor* chunk id of %0X\n",EDIT3DS);
  1814.                       #endif
  1815.                       tellertje+=ReadEditChunk ();
  1816.                       break;
  1817.         default:      break;
  1818.        }
  1819.  
  1820.    tellertje+=2;
  1821.    if (tellertje>=temp_pointer)
  1822.     end_found=TRUE;
  1823.  }
  1824.  
  1825.  ChangeChunkPointer (current_pointer+temp_pointer); // move to the new chunk position
  1826.  return (temp_pointer);
  1827. }
  1828. /*----------------------------------------------------------------------------*/
  1829. int ReadPrimaryChunk (void)
  1830. {
  1831.  unsigned char version;
  1832.  
  1833.  if (ReadInt ()==MAIN3DS)
  1834.  {
  1835.   #ifdef __DEBUG__
  1836.   printf ("> Found Main chunk id of %0X\n",MAIN3DS);
  1837.   #endif
  1838.   //>---------- find version number
  1839.   fseek (bin3ds,28L,SEEK_SET);
  1840.   version=ReadChar ();
  1841.   if (version<3)
  1842.   {
  1843.    #ifdef __DEBUG__
  1844.    printf ("Sorry this lib can only read 3ds files of version 3.0 and higher\n");
  1845.    printf ("The version of the file you want to read is: %d\n",version);
  1846.    #endif
  1847.    return (1);
  1848.   }
  1849.   fseek (bin3ds,2,SEEK_SET);
  1850.   ReadMainChunk ();
  1851.  }
  1852.  else
  1853.   return (1);
  1854.  
  1855.  return (0);
  1856. }
  1857. /*----------------------------------------------------------------------------*/
  1858. /*                      Test Main for the 3ds-bin lib                         */
  1859. /*----------------------------------------------------------------------------*/
  1860. int main (int argc,char **argv)
  1861. {
  1862.  argc=argc;
  1863.  
  1864.  bin3ds=fopen (argv [1],"rb");
  1865.  if (bin3ds==NULL)
  1866.   return (-1);
  1867.  
  1868.  #ifdef __DEBUG__
  1869.  printf ("\nLoading 3ds binary file : %s\n",argv [1]);
  1870.  #endif
  1871.  while (ReadPrimaryChunk ()==0);
  1872.  
  1873.  return (0);
  1874. }
  1875. /*----------------------------------------------------------------------------*/
  1876. #endif
  1877. ---------------------------------47423551520711978481135565041--
  1878.